home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / util / misc / Fudgit233.lha / Source / src / chd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-14  |  1.3 KB  |  75 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #ifndef NOUNISTD_H
  4. #include <unistd.h>
  5. #endif
  6. #include "fudgit.h"
  7. #include "head.h"
  8.  
  9. #ifndef HPUX
  10. extern char *getwd(char *);
  11. #endif
  12.  
  13. static int Cwdlevel = 0;
  14. static char Path[MAXLEVEL+2][PATH_MAXIM];
  15.  
  16. extern char Ft_Cwd[PATH_MAXIM];
  17.  
  18. extern int chdir (const char *);
  19. extern int Ft_filelevel (void);
  20.  
  21. int Ft_push_cwd(void)
  22. {
  23. #ifdef HPUX
  24.     if (getcwd(Path[Cwdlevel], PATH_MAXIM-1) == (char *)NULL) {
  25.         perror("getcwd");
  26.         return(ERRR);
  27.     }
  28. #else
  29.     if (getwd(Path[Cwdlevel]) == (char *)NULL) {
  30.         fprintf(stderr, "%s\n", Path[Cwdlevel]);
  31.         return(ERRR);
  32.     }
  33. #endif
  34.     strcpy(Ft_Cwd, Path[Cwdlevel]);
  35.     if (++Cwdlevel > MAXLEVEL) {
  36.         fputs("Error: Cwd stack overflow.\n", stderr);
  37.         Ft_catcher(ERRR);
  38.     }
  39.     return(0);
  40. }
  41.  
  42. int Ft_pop_cwd(void)
  43. {
  44.     if (Cwdlevel < 1) {
  45.         fputs("Error: Cwd stack underflow.\n", stderr);
  46.         Ft_catcher(ERRR);
  47.     }
  48.     if (chdir(Path[--Cwdlevel]) == ERRR) {
  49.         perror("");
  50.         return(ERRR);
  51.     }
  52.     strcpy(Ft_Cwd, Path[Cwdlevel]);
  53.     return(0);
  54. }
  55.  
  56. int Ft_clearpop_cwd(void)
  57. {
  58.     Cwdlevel = 1;
  59.     if (chdir(Path[0]) == ERRR) {
  60.         perror("");
  61.         return(ERRR);
  62.     }
  63.     strcpy(Ft_Cwd, Path[0]);
  64.     return(0);
  65. }
  66.  
  67. int Ft_clearpush_cwd(void)
  68. {
  69.     if (!Ft_filelevel()) {
  70.         Cwdlevel = 0;
  71.         return(Ft_push_cwd());
  72.     }
  73.     return(0);
  74. }
  75.